package edu.hunau.cxb19.oop.class30;

import org.junit.Test;

/**
 *
 * @author hb
 *
 *         2020-04-14 14:44:22
 */
public class ThreadPriorityTest {

	@Test
	public void test01() {
		Thread t1 = new Thread(() -> {
			for (int i = 0; i < 10; i++) {
				System.out.println("\t " + Thread.currentThread().getName() +"[ "+Thread.currentThread().getPriority() +" ]:i=" + i);
			}
		}, "my-thread-01");
		//指定线程的优先级，指定t1的线程的优先级为最高级
		//必须先指定线程的优先级然后再启动线程
		t1.setPriority(Thread.MAX_PRIORITY);
		
		Thread t2 = new Thread(() -> {
			for (int i = 0; i < 10; i++) {
				System.out.println(Thread.currentThread().getName() +"[ "+Thread.currentThread().getPriority() +" ]:i=" + i);
			}
		}, "my-thread-02");

		t2.setPriority(Thread.MIN_PRIORITY);
		
		t1.start();
		t2.start();
	}
}
